package ils.aquisition.web.action;

import ils.domain.acquisition.model.DeliveryFactory;
import ils.domain.acquisition.model.DeliveryItem;
import ils.web.model.WDelivery;
import ils.web.model.WDeliveryItem;
import ils.services.AquisitionCommon;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.opensymphony.xwork2.ActionSupport;

public class RecordDeliveryAction extends ActionSupport
{
    private static final long serialVersionUID = 1L;
    private int sellerId;
    private Map<Integer, WDeliveryItem> deliveryItems = new HashMap<Integer, WDeliveryItem>();
    private DeliveryFactory deliveryFactory;
    private AquisitionCommon aquisitionCommon;
    @Override
    public String execute() throws Exception
    {
        if(deliveryItems == null || sellerId == 0) return INPUT;
        List<WDeliveryItem> wDeliveryItems = new ArrayList<WDeliveryItem>(deliveryItems.values());
        Set<DeliveryItem> deliveryItemList = aquisitionCommon.convertToDeliveryItems(wDeliveryItems);
        WDelivery wDelivery = new WDelivery();
        wDelivery.setSellerId(sellerId);
        wDelivery.setItems(deliveryItemList);
        return SUCCESS;
    }
    public int getSellerId()
    {
        return sellerId;
    }
    public void setSellerId(int sellerId)
    {
        this.sellerId = sellerId;
    }
    public Map<Integer, WDeliveryItem> getDeliveryItems()
    {
        return deliveryItems;
    }
    public void setDeliveryItems(Map<Integer, WDeliveryItem> deliveryItems)
    {
        this.deliveryItems = deliveryItems;
    }
    public void setDeliveryFactory(DeliveryFactory deliveryFactory)
    {
        this.deliveryFactory = deliveryFactory;
    }
    public void setAquisitionCommon(AquisitionCommon aquisitionCommon)
    {
        this.aquisitionCommon = aquisitionCommon;
    }
}
